<?php
// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2']| !$_POST['name'] | !$_POST['gender'] | !$_POST['dob'] | !$_POST['phone'] | !$_POST['altemail'] ) {
die('You did not complete all of the required fields');
}


// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$password = addslashes($_POST['pass']);
$login_id = addslashes($_POST['username']);
}

$name = $_POST['name'];

if ($_POST['gender'] == 'male') {
$gender = 'M';
}
else if ($_POST['gender'] == 'female') {
$gender = 'F';
}
$dob = $_POST['dob']; 

list($year, $month, $day, ) = split('[/.-]', $dob);

//echo $year;

if ($year == '0000'){
	die('Please enter a valid year of birth and try again');
}
$phone = $_POST['phone'] ;
$alt_email = $_POST['altemail'];
$img = $_POST['image'];

// now we insert it into the database
$insert = "INSERT INTO user (login_id, pwd, name, user_phone, alt_email, gender, dob, image_url)
VALUES ('$login_id', '$password', '$name', '$phone', '$alt_email','$gender','$dob','$img')";
$add_member = mysql_query($insert) or die(mysql_error());
?>
<h1>Registered</h1>
<?php
}
else
{
?>


<h1>Error!!!</h1>
<?php
}
?> 
